<template>
  <div class="teamWorkDetail-page">
    <div class="header">
      <span style="margin-right: 20px">明细</span>
      <el-button
        @click="onBJ"
        round
        size="mini"
        type="success"
        icon="el-icon-check"
      >
        标 &ensp; 记&ensp;
      </el-button>
      <el-button
        @click="onQXBJ"
        round
        size="mini"
        type="success"
        icon="el-icon-close"
        >取消标记</el-button
      >
      <el-button
        @click="onTT"
        round
        size="mini"
        type="success"
        icon="el-icon-picture-outline"
      >
        挑 图
      </el-button>
      <el-button
        @click="onPack"
        round
        size="mini"
        type="success"
        icon="el-icon-files"
      >
        打 包
      </el-button>
    </div>
    <div class="body">
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        header-align="center"
        @selection-change="handleSelectionChange"
      >
        <el-table-column fixed type="selection" align="center">
        </el-table-column>
        <el-table-column
          prop="Picker"
          label="标记者"
          width="120"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="PickTime" label="标记时间" align="center">
        </el-table-column>
        <el-table-column
          prop="FBILLNO"
          label="单据号"
          width="120"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="MaterialCode"
          label="物料编码"
          width="120"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="MaterialName"
          label="物料名称"
          width="120"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="Spec"
          label="规格型号"
          width="120"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="BaseUnit"
          label="基本单位"
          width="120"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="zip" label="文件名称" width="120" align="center">
        </el-table-column>
        <el-table-column prop="zip" label="申请数量" width="120" align="center">
        </el-table-column>
        <el-table-column prop="zip" label="批准数量" width="120" align="center">
        </el-table-column>

        <el-table-column prop="zip" label="备注" width="120" align="center">
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="100" align="center">
          <template> </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryData.intPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="queryData.number"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { geteDLineListApi } from "@/api/teamWork";
import { getImportPurchaseListApi, PurchaseApiApi } from "@/api/procurement";
export default {
  data() {
    return {
      tableData: [],
      queryData: {
        number: 10,
        intPage: 1,
        idStr: "",
      },
      total: 0,
      selecteList: [],
    };
  },
  created() {
    this.queryData.idStr = this.$route.query.data.join(",");
    console.log(this.$route.query);
    this.geteDLineList();
  },
  methods: {
    async geteDLineList() {
      const res = await geteDLineListApi(this.queryData);
      console.log(res);
      this.tableData = res.data.rows;
      this.total = res.data.total;
    },
    handleSelectionChange(rows) {
      console.log(rows);
      this.selecteList = rows;
    },
    async onBJ() {
      if (!this.selecteList.length) {
        this.$message.warning("请先选择数据");
        return;
      }

      this.list = this.selecteList.map((ele) => ele.ID);
      console.log(list);
      const res = await PurchaseApiApi({
        postpara: {
          posttype: "ComsurePickByList",
        },
        ureentity: this.list,
        ComsurePickUser: "admin",
      });
      console.log(res);
      this.geteDLineList();
    },
    async onQXBJ() {
      if (!this.selecteList.length) {
        this.$message.warning("请先选择数据");
        return;
      }
      this.list = this.selecteList.map((ele) => ele.ID);
      const res = await PurchaseApiApi({
        postpara: {
          posttype: "CancelPickByList",
        },
        ureentity: this.list,
        CancelPickUser: "admin",
      });
      console.log(res);
      this.geteDLineList();
    },
    async onTT() {
      if (!this.selecteList.length) {
        this.$message.warning("请先选择数据");
        return;
      }
      // if (this.isBJ) {
      const MaterialCodelist = this.selecteList.map((ele) => {
        return ele.MATERIALCODE;
      });
      console.log(MaterialCodelist);

      MaterialCodelist.forEach(async (ele) => {
        const res = await PurchaseApiApi({
          postpara: {
            posttype: "PickPhoto",
          },
          MaterialCode: ele,
          PickUser: "admin",
        });
        const data = JSON.parse(res.data);
        console.log(data);

        for (const item of this.selecteList) {
          item.FileName = data.FileName;
        }
      });
      // } else {
      //   this.$message("请先进行标记操作");
      // }
    },
    onPack() {
      if (!this.selecteList.length) {
        this.$message.warning("请先选择数据");
        return;
      }
      // if (this.isBJ) {
      this.$router.push({
        path: "/pack",
        query: { list: this.selecteList },
      });
      // } else {
      //   this.$message("请先进行标记操作");
      // }
    },
    handleSizeChange(val) {
      this.queryData.number = val;
      this.geteDLineList();
    },
    handleCurrentChange(val) {
      this.queryData.intPage = val;
      this.geteDLineList();
    },
  },
};
</script>

<style lang="scss" scoped>
.teamWorkDetail-page {
  background-color: #fff;

  .header {
    padding: 20px 30px;
  }
  .body {
    padding: 20px;
  }
}
</style>